<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/
include("functions.php");
include("cnnxn.php");
connect();

if (isset($_GET['did'])) {
	$SQLview='SELECT * FROM av_players WHERE divisionid='.$_GET['did'].' ORDER BY fullname ASC;';
	$sendit_view=mysqli_query($db,$SQLview) or die(mysqli_error($db));

	$SQLdt='SELECT * FROM av_divisions WHERE id='.$_GET['did'].';';
	$sendit_dt=mysqli_query($db,$SQLdt) or die(mysqli_error($db));
	$RSdt=mysqli_fetch_object($sendit_dt);
} else {	
	$SQLview='SELECT * FROM av_players ORDER BY fullname ASC;';
	$sendit_view=mysqli_query($db,$SQLview) or die(mysqli_error($db));
}
	
$SQLd='SELECT * FROM av_divisions;';
$sendit_d=mysqli_query($db,$SQLd) or die(mysqli_error($db));

$SQLo='SELECT * FROM av_organization;';
$sendit_o=mysqli_query($db,$SQLo) or die(mysqli_error($db));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>daleclark.net</title>
<link type="text/css" rel="stylesheet" href="adminstyles.css" />
</head>
<body>
<div id="adminwrapper">
<div id="adminlogo"></div>
<?PHP navigation(); ?>
<div id="admincontent">
<?PHP
if (isset($_GET['did'])) {
	print '<h3>Players in '.$RSdt->divisionname.'</h3>';
} else {
	print '<h3>Players</h3>';
}
?>

<div style="float:left; width:500px; padding-right:25px; margin-right:25px; border-right:1px solid #FFFFFF;">

<?PHP 
$backgroundcolor="#2883D4"; 
while ($RSview=mysqli_fetch_object($sendit_view)) {
	if ($backgroundcolor=="#2883D4") {
		$backgroundcolor="#2F93E9";
	} else {
		$backgroundcolor="#2883D4";
	}
	$divid='';
	if (isset($_GET['did'])) {
		$divid='&did='.$_GET['did'];
	}
	print '<div style="background:'.$backgroundcolor.'; width:500px; padding:2px 2px 2px 5px;"><span class="deletespan"><a href="av_players_del.php?id='.$RSview->id.$divid.'" class="deletelink" title="DELETE" onclick="return confirm(\'Are sure you want to PERMANENTLY DELETE this Player? This will NOT affect previous event records and results.\')"><img src="../images/icon_delete.png" height="12px" border="0" /></a></span><span class="column01span"><a href="av_players_mod.php?id='.stripslashes($RSview->id).$divid.'" title="Modify This Player">'.$RSview->fullname.' - ';
	if (!isset($_GET['did'])) {
		$SQLsd='SELECT * FROM av_divisions WHERE id='.$RSview->divisionid.';';
		$sendsd=mysqli_query($db,$SQLsd) or die(mysqli_error($db));
		$RSsd=mysqli_fetch_object($sendsd);
		print $RSsd->divisionname.', ';
	}
	print 'Rating: '.$RSview->rating.'</a></span><div class="clear"></div></div>';
}
?>

<div class="clear"></div>
<p>&nbsp;</p>
</div>
<div style="float:left; width:500px;">

<h3>Add a Player</h3>
<form name="addForm" method="POST" action="av_players_add.php<?PHP if (isset($_GET['did'])) { print '?did='.$_GET['did']; } ?>">
<p><span class="label">Full Name</span><span class="inputbox"><input name="fullname" type="text" /></span></p>
<p><span class="label">Organization</span><span class="inputbox"><select name="organizationid">
<option value="">...</option>
<?PHP
while ($RSo=mysqli_fetch_object($sendit_o)) {
	print '<option value="'.$RSo->id.'">'.$RSo->orgname.'</option>';
}
?>
</select></span> <a href="av_organization_viewall.php" style="font-weight:normal; color:#000099">+ new</a></p>
<p><span class="label">Division</span><span class="inputbox"><select name="divisionid">
<?PHP
while ($RSd=mysqli_fetch_object($sendit_d)) {
	print '<option value="'.$RSd->id.'"';
	if (isset($_GET['did']) && $_GET['did']==$RSd->id) {
		print ' selected';
	}
	print '>'.$RSd->divisionname.'</option>';
}
?>
</select></span></p>
<p><span class="label">Rating</span><span class="inputbox"><select name="rating">
<option value="" selected>...select if applicable</option><option value="A">A</option><option value="AA">AA</option><option value="AAA">AAA</option>
</select></span></p>
<input type="submit" value="submit" name="submit" />
</form>

</div>


</div>
</div>
</body>
</html>
<?PHP
mysqli_close($db);
?>
<?PHP
mysqli_close($db);
?>